import Vue from 'vue'
import Router from 'vue-router'
const _import = require('./_import')
Vue.use(Router)

/* Layout */
import Layout from '../views/layout/Layout'
/**
* hidden: true                   if `hidden:true` will not show in the sidebar(default is false)
* alwaysShow: true               if set true, will always show the root menu, whatever its child routes length
*                                if not set alwaysShow, only more than one route under the children
*                                it will becomes nested mode, otherwise not show the root menu
* redirect: noredirect           if `redirect:noredirect` will no redirct in the breadcrumb
* name:'router-name'             the name is used by <keep-alive> (must set!!!)
* meta : {
    roles: ['admin','editor']     will control the page roles (you can set multiple roles)
    title: 'title'               the name show in submenu and breadcrumb (recommend set)
    icon: 'svg-name'             the icon show in the sidebar,
    noCache: true                if true ,the page will no be cached(default is false)
  }
**/
export const constantRouterMap = [
  { path: '/login', component: _import('login/index'), hidden: true },
  { path: '/authredirect', component: _import('login/authredirect'), hidden: true },
  { path: '/404', component: _import('errorPage/404'), hidden: true },
  { path: '/401', component: _import('errorPage/401'), hidden: true },
  {
    path: '',
    component: Layout,
    redirect: 'dashboard',
    children: [{
      path: 'dashboard',
      component: _import('dashboard/index'),
      name: 'dashboard',
      meta: { title: 'dashboard', icon: 'dashboard', noCache: true }
    }]
  }
]

// 非根目录配置 (本地需要注释掉)
export default new Router({
  mode: 'history', // require service support
  base: '/manage', // 线上需要注释掉
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRouterMap
})

// 权限路由,展示部分
export const asyncRouterMap = [
  // 用户管理
  {
    path: '/users',
    component: Layout,
    alwaysShow: true,
    meta: { title: '客户管理', icon: 'peoples' },
    children: [{ path: 'index', component: _import('users/index'), name: 'users', meta: { title: '客户列表', icon: 'people', roles: ['indexUser'] }}] // or you can only set roles in sub nav
  },
  // 商品管理
  {
    path: '/product',
    component: Layout,
    alwaysShow: true,
    meta: { title: '商品/类别', icon: 'example' }, // you can set roles in root nav
    children: [
      { path: 'index', name: 'productIndex', meta: { title: '商品列表', icon: 'example', roles: ['indexProduct'] }, component: _import('product/index') }, // or you can only set roles in sub nav
      { path: 'edit-product', name: 'editProduct', meta: { title: '商品编辑', roles: ['editProduct'] }, component: _import('product/editProduct'), hidden: true },
      { path: 'product-category', name: 'productCategory', meta: { title: '商品类别', icon: 'example', roles: ['indexCategory'] }, component: _import('product/category') },
      { path: 'categories', name: 'categories', meta: { title: '类别管理', icon: 'example', roles: ['categories'] }, component: _import('product/mainCategory') },
      { path: 'search-barcode', name: 'searchBarCodeProduct', meta: { title: '条形码设置', icon: 'example', roles: ['searchBarCodeProduct'] }, component: _import('product/searchBarCode') }
    ]
  },
  // 站点(营业点)管理
  {
    path: '/outlets',
    component: Layout,
    alwaysShow: true,
    meta: { title: '营业点管理', icon: 'component' }, // you can set roles in root nav
    children: [
      { path: 'outlet-config', name: 'outletConfig', meta: { title: '店铺设置', roles: ['userOutlet'] }, component: _import('outlets/outletConfig') },
      { path: 'outlet-index', name: 'indexOutlet', meta: { title: '营业点列表', roles: ['indexOutlet'] }, component: _import('outlets/index') },
      { path: 'edit-outlet', name: 'editOutlet', meta: { title: '营业点编辑', roles: ['editOutlet'] }, component: _import('outlets/editOutlet'), hidden: true },
      { path: 'withdraw-check', name: 'withdrawCheck', meta: { title: '提现列表', roles: ['withdrawCheck'] }, component: _import('outlets/withdrawCheck') },
      { path: 'outlet-withdraw', name: 'outletWithdraw', meta: { title: '提现列表(加盟)', roles: ['outletWithdraw'] }, component: _import('outlets/outletWithdraw') },
      { path: 'symbol-list', name: 'symbolList', meta: { title: '点餐码列表', roles: ['symbolList'] }, component: _import('symbol/index') }
    ]
  },
  // 订单管理
  {
    path: '/orders',
    component: Layout,
    alwaysShow: true,
    meta: { title: '订单管理', icon: 'shoppingCard' }, // you can set roles in root nav
    children: [
      { path: 'orders-index', component: _import('orders/index'), name: 'ordersIndex', meta: { title: '订单列表', roles: ['indexOrder'] }},
      { path: 'order-payment', component: _import('orders/orderPayment'), name: 'orderPayment', meta: { title: '模拟下单', roles: ['orderPayment'] }}
    ]
  },
  // 提成统计
  {
    path: '/reports',
    component: Layout,
    alwaysShow: true,
    meta: { title: '接单统计', icon: 'chart' }, // you can set roles in root nav
    children: [
      { path: 'courier-report', name: 'courierReport', meta: { title: '配送员账单', roles: ['courierReport'] }, component: _import('orders/courierReport') },
      { path: 'reseller-report', name: 'resellerReport', meta: { title: '代理账单', roles: ['resellerReport'] }, component: _import('orders/resellerReport') },
      { path: 'outlet-report', name: 'outletReport', meta: { title: '加盟点账单', roles: ['outletReport'] }, component: _import('orders/outletReport') },
      { path: 'bill-config', name: 'billConfig', meta: { title: '提成配置', roles: ['billConfig'] }, component: _import('orders/billConfig') },
      { path: 'unit-bill-config', name: 'unitbillConfig', meta: { title: '站点配置', roles: ['unitBill'] }, component: _import('orders/unitBillConfig') }
    ]
  },
  // 图片管理
  {
    path: '/phone',
    component: Layout,
    name: '/phone',
    alwaysShow: true,
    meta: { title: '图片相册', icon: 'tab' },
    children: [
      { path: 'photo-index', component: _import('image/index'), name: 'photoIndex', meta: { title: ' 图片列表', roles: ['indexPhoto'] }} // meta: { title: ' 图片列表', noCache: true }
    ]
  },
  // 交际圈管理
  {
    path: '/social',
    component: Layout,
    name: '/social',
    alwaysShow: true,
    meta: { title: '交际圈管理', icon: 'international' },
    children: [
      { path: 'index-informa', component: _import('social/informa'), name: 'socialIndex', meta: { title: '信息列表', roles: ['indexInforma'] }}, // meta: { title: ' 图片列表', noCache: true }
      { path: 'index-infocate', component: _import('social/infoCate'), name: 'infocate', meta: { title: '标签列表', roles: ['indexInfocate'] }},
      { path: 'info_cashtype', component: _import('social/infoCashtype'), name: 'infocashtype', meta: { title: '费用配置', roles: ['infoCashtype'] }}
      // { path: 'photo-index', component: _import('image/index'), name: 'socialIndex3', meta: { title: '收费统计', roles: ['index_photo'] }}
    ]
  },
  // 权限分配
  {
    path: '/permission',
    component: Layout,
    alwaysShow: true,
    meta: { title: '用户管理', icon: 'lock' },
    children: [
      { path: 'permission-admin', name: 'permissionAdmin', meta: { title: '管理员列表', roles: ['indexAdmin'] }, component: _import('permission/index') },
      { path: 'permission-role', name: 'permissionRole', meta: { title: '角色列表', roles: ['indexRole'] }, component: _import('permission/roles') },
      { path: 'edit-role', name: 'editRole', meta: { title: '角色编辑', roles: ['editRole'] }, component: _import('permission/editRole'), hidden: true }
    ]
  },
  // 系统配置
  {
    path: '/system',
    component: Layout,
    alwaysShow: true,
    meta: { title: '系统配置', icon: 'lock' },
    children: [
      { path: 'device-list', name: 'deviceList', meta: { title: '设备管理' }, roles: ['deviceList'], component: _import('devices/index') },
      { path: 'system-menu', name: 'systemMenu', meta: { title: '菜单管理', roles: ['indexPermission'] }, component: _import('dashboard/systemMenu') },
      { path: 'other-setup', name: 'otherSetup', meta: { title: '其他设置', roles: ['indexPermission'] }, component: _import('dashboard/otherSetup') }
    ]
  },
  { path: '*', redirect: '/404', hidden: true }
]
